package com.by.controller.house;

import com.by.bean.house.House;
import com.by.bean.params.TowerQuery;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.service.house.HouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "房屋管理")
@RequestMapping("/api")
public class HouseController extends BaseController {


    @Autowired
    HouseService houseService;


    @ApiOperation("新增房屋")
    @PostMapping("/house")
    public ResultBean save(@RequestBody House house) {
        int rs = houseService.save(house);
        return saveResult(rs);
    }

    @ApiOperation("批量删除房屋")
    @DeleteMapping("/house")
    public ResultBean deleteAll(@RequestParam List<Integer> list){
        int rs = houseService.deleteAll(list);
        return deleteResult(rs);
    }

    @ApiOperation("修改房屋")
    @PutMapping("/house")
    public ResultBean update(@RequestBody House house){
        int rs = houseService.update(house);
        return updateResult(rs);
    }

    @ApiOperation("房屋列表")
    @PostMapping("/house/query")
    public ResultBean query(@RequestBody TowerQuery query) {
        PageBean bean = houseService.query(query.toMap());
        return success("房屋列表", bean);
    }

    @ApiOperation("房屋详情")
    @GetMapping("/house")
    public ResultBean get(int id){
        House house = houseService.get(id);
        return success("房屋详情", house);
    }
}
